// 用户数据模块
import http from '@/shopro/request/index'

const state = {
    token: uni.getStorageSync('token') || '',
    isLogin: uni.getStorageSync('isLogin') || false, // 是否登陆
    userInfo: uni.getStorageSync('userInfo') || {}, // 用户信息
    authType: '', // smsLogin:手机号登录注册, accountLogin:密码登录, forgotPwd:忘记密码, changePwd:修改密码, bindMobile:绑定手机号
}

const getters = {
    token: (state) => state.token,
    isLogin: (state) => state.isLogin,
    userInfo: (state) => state.userInfo,
    authType: (state) => state.authType,
}

const actions = {
    // 初始化数据
    async appInit({ commit, dispatch }, options) {
        const result = await http('common.init')
        // 触发 actions
        // dispatch('autoLogin')

        // 触发 mutations
        // commit('CONFIG', result.data)
    },

    // 登录弹窗控制
	showAuthModal({
		commit
	}, type = 'accountLogin') {
		commit('AUTH_TYPE', type);
	},
}

const mutations = {
    AUTH_TYPE(state, data) {
		data ? uni.hideTabBar() : uni.showTabBar();
		state.authType = data;
	},
}

export default {
    state,
    mutations,
    actions,
    getters
}
